#include <vector>
class Solution {
public:
    int rob(vector<int>& nums) {
        //dp解决f[i]代表我不偷取当前屋子的最高现金
        //g[i]代表我偷当前屋子的最高现金
        int n = nums.size();
        vector<int> g(n,0);
        vector<int> f(n,0);
        g[0] = nums[0];
        int ret = 0;
        for(int i = 1;i<n;i++)
        {
            g[i] = max(f[i-1]+nums[i],f[i-1]);
            f[i] = max(f[i-1],g[i-1]);
            ret = max(g[i],f[i]);
        }
        if(ret == 0)
        {
            return g[0];
        }
        return ret;
    }
};